<template>
  <div class="container">
    <div class="content">
      <div class="topBox">
        <div class="left">
          <el-button
            v-permission="'userManagementAdd'"
            class="btnColor"
            @click="addMenu()"
            >添加+</el-button
          >
        </div>
        <!-- <div class="right">
          <el-input v-model="searchInput" placeholder="请输入账号或角色" />
          <el-button icon="el-icon-search" class="btnColor">查询</el-button>
        </div> -->
      </div>
      <div class="tableBox">
        <el-table
          v-loading="loading"
          :data="tableData"
          style="width: 100%"
          row-key="id"
          border
          default-expand-all
          :tree-props="{ children: 'menuList', hasChildren: 'hasChildren' }"
        >
          <el-table-column
            align="left"
            prop="menuName"
            label="菜单名称"
            width="300"
          />
          <el-table-column
            align="center"
            prop="path"
            label="菜单编码"
            width="300"
          />
          <el-table-column
            align="center"
            prop="menuTypeName"
            label="节点类型"
          />

          <el-table-column
            align="center"
            prop="address"
            label="操作"
            width="260"
          >
            <template slot-scope="scope">
              <div class="btnBox">
                <div
                  slot="reference"
                  class="editBtn1"
                  v-permission="'menuManagementSee'"
                  @click="addMenu(scope.row.id)"
                >
                  <i class="el-icon-edit" />查看详情
                </div>
                <div
                  slot="reference"
                  class="editBtn3"
                  type="text"
                  v-permission="'menuManagementDel'"
                  @click="delDetail(scope.row.id)"
                >
                  <i class="el-icon-delete" />
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import { getMenuList, menuDelete } from "@/api/systemManagement";
export default {
  name: "MenuManagement",
  data() {
    return {
      searchInput: "",
      tableData: [],
      titleName: "菜单管理",
      loading: true,
    };
  },
  created() {
    this.GetMenuTreeList();
  },
  methods: {
    async GetMenuTreeList() {
      const res = await getMenuList();
      this.tableData = res.data;
      this.loading = false;
    },

    addMenu(id) {
      this.$router.push({ path: "/menuDetail", query: { menuId: id } });
    },
    async delDetail(id) {
      this.$confirm("此操作将永久删除该菜单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          await menuDelete({ id: id });
          this.GetMenuTreeList();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.container {
  background-color: #f8fafc;
  padding: 10px;

  .btnColor {
    background-color: #0077FF;
    color: #fff;
    margin-left: 10px;
  }
  .content {
    background-color: #fff;
    padding: 20px 10px;
    .topBox {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 40px;
      .right {
        display: flex;
      }
    }
    .tableBox {
      padding: 10px 40px;
      ::v-deep .el-table th,
      .el-table tr {
        background-color: #f6f9f8 !important;
        color: #333 !important;
        height: 30px;
      }
      ::v-deep .el-table__row {
        height: 50px !important;
        padding: 0 !important;
      }
      ::v-deep .el-table th,
      .el-table tr {
        height: 50px !important;
      }
      ::v-deep .el-table td,
      .el-table th {
        padding: 0 !important;
        padding-top: 5px !important;
      }

      .btnBox {
        display: flex;
        align-items: center;
        justify-content: center;

        .editBtn1 {
          cursor: pointer;
          background-color: #0077FF;
          color: #fff;
          // width: 25px;
          padding: 0 10px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          border-radius: 5px;
        }
        .editBtn2 {
          cursor: pointer;
          margin-left: 10px;
          background-color: #ffa426;
          padding: 0 10px;
          color: #fff;
          height: 25px;
          line-height: 25px;
          text-align: center;
          border-radius: 5px;
        }
        .editBtn3 {
          cursor: pointer;
          margin-left: 10px;
          background-color: #d72e2e;
          width: 25px;
          color: #fff;
          height: 25px;
          line-height: 25px;
          text-align: center;
          border-radius: 5px;
        }
      }

      .footerPage {
        padding: 0 30px 0 0;
        display: flex;
        justify-content: right;
        width: 100%;
        background-color: #f8fafc;
        height: 50px;
        align-items: center;
        margin-top: 10px;

        //  ::v-deep .el-pagination .btn-next, .el-pagination .btn-prev{
        //   background-color: #087 !important;
        // }
      }
    }
  }
}
</style>
